<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>发送ajax请求</button>
    <script>
        let oBtn = document.querySelector('button');
        oBtn.onclick = function(){
            console.log('1111');
            // 1. 创建xhr对象
            const xhr = new XMLHttpRequest();
            // 2. 打开链接  get  /query
            xhr.open('get', 'http://localhost:8080/query?username=atguigu&age=20');
            // 3. 发送请求
            xhr.send();
            // 4. 监听
            xhr.onreadystatechange = function(){
                if(xhr.readyState === 4) {
                    if(/^2\d{2}$/.test(xhr.status)){
                        console.log(xhr.response);
                    }
                }
            }
        }
    </script>
</body>
</html>